Function.RegisterNamespace("Test.xUnit.js.Model");

[Fixture]
Test.xUnit.js.Model.Fixture=function(){
    [Fixture]
    function FixtureTest(){
        [Fact]
        function InitializesEvents(){
            var actual=new xUnit.js.Model.Fixture();
            
            Assert.NotNull(actual.Events);
        }
        
        [Fact]
        function SetsNameFromParameter(){
            var expected="FixtureNameOverride";
            
            var actual=new xUnit.js.Model.Fixture(expected);
            
            Assert.Equal(expected,actual.Name);
        }
        
        [Fact]
        function SetsNameToAnonymousIfNoParameterIsPassed(){
            var expected="[Anonymous]";
            
            var actual=new xUnit.js.Model.Fixture();
            
            Assert.Equal(expected,actual.Name);
        }
    }

    [Fixture]
    function AddMock(){
        [Fact]
        function ThrowsIfMockIsOmitted(){
            var expected="xUnit.js.Model.Fixture.AddMock: 'mock' must be a valid mockery.";
            var target=new xUnit.js.Model.Fixture(function(){});

            var actual=Record.Exception(function(){
                target.AddMock();
            });

            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ThrowsIfMockIsInvalid(){
            var expected="xUnit.js.Model.Fixture.AddMock: 'mock' must be a valid mockery.";
            var target=new xUnit.js.Model.Fixture(function(){});

            var actual=Record.Exception(function(){
                target.AddMock(function(){});
            });

            Assert.Equal(expected,actual);
       
        }

        [Fact]
        function AddsMock(){
            var expected=[Mocks.GetMock(Object.Global(),"expected",{mock:"mock"})];
            var target=new xUnit.js.Model.Fixture(function(){});
            
            target.AddMock(expected[0]);
            var actual=target.GetMocks();

            Assert.Equal(expected,actual);
        }

        [Fact]
        function AddsMultipleMocks(){
            var expected=[
                Mocks.GetMock(Object.Global(),"expected1",{mock1:"mock1"}),
                Mocks.GetMock(Object.Global(),"expected2",{mock1:"mock2"}),
                Mocks.GetMock(Object.Global(),"expected3",{mock1:"mock3"})
            ];
            var target=new xUnit.js.Model.Fixture(function(){});
            
            target.AddMock(expected[0]);
            target.AddMock(expected[1]);
            target.AddMock(expected[2]);
            var actual=target.GetMocks();

            Assert.Equal(expected,actual);
        }
    }

    [Fixture]
    function GetMocks(){
        [Fact]
        function ReturnsMocksFromFixture(){
            var expected=[
                Mocks.GetMock(Object.Global(),"expected1",{mock1:"mock1"}),
                Mocks.GetMock(Object.Global(),"expected2",{mock1:"mock2"}),
                Mocks.GetMock(Object.Global(),"expected3",{mock1:"mock3"})
            ];
            var target=new xUnit.js.Model.Fixture(function(){});
            target.AddMock(expected[0]);
            target.AddMock(expected[1]);
            target.AddMock(expected[2]);

            var actual=target.GetMocks();

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ReturnsMocksFromParent(){
            var expected=[
                Mocks.GetMock(Object.Global(),"expected1",{mock1:"mock1"}),
                Mocks.GetMock(Object.Global(),"expected2",{mock1:"mock2"}),
                Mocks.GetMock(Object.Global(),"expected3",{mock1:"mock3"})
            ];
            var target=new xUnit.js.Model.Fixture(function(){});
            target.Parent=new xUnit.js.Model.Fixture();
            target.Parent.AddMock(expected[0]);
            target.Parent.AddMock(expected[1]);
            target.Parent.AddMock(expected[2]);

            var actual=target.GetMocks();

            Assert.Equal(expected,actual);
        }

        [Fact]
        function ReturnsMocksFromGrandParent(){
            var expected=[
                Mocks.GetMock(Object.Global(),"expected1",{mock1:"mock1"}),
                Mocks.GetMock(Object.Global(),"expected2",{mock1:"mock2"}),
                Mocks.GetMock(Object.Global(),"expected3",{mock1:"mock3"})
            ];
            var target=new xUnit.js.Model.Fixture(function(){});
            target.Parent=new xUnit.js.Model.Fixture();
            target.Parent.Parent=new xUnit.js.Model.Fixture();
            target.Parent.Parent.AddMock(expected[0]);
            target.Parent.Parent.AddMock(expected[1]);
            target.Parent.Parent.AddMock(expected[2]);

            var actual=target.GetMocks();

            Assert.Equal(expected,actual);
        }

    }
}